package com.bookcloud.java21.chapter4.类的this关键字46;

public class ThisKeywordExample {
  // 定义一个属性name
  private String name;
  // 定义一个属性age
  private int age;

  // 使用this赋值成员变量
  public void init(String name, int age) {
    this.name = name;
    this.age = age;
  }

  public void printThisAddr() {
    System.out.println("&this:" + this);
  }

  // 构造函数，this
  public ThisKeywordExample() {
    this("未知", 0);
  }

  // 3个参数的构造函数
  public ThisKeywordExample(String name, int age) {
    this.name = name;
    this.age = age;
  }

  // 返回当前对象
  public ThisKeywordExample getThis() {
    return this;
  }
}
